using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using NotAClue.EF.Auditing.Models.Mapping;

namespace NotAClue.EF.Auditing.Models
{
    public class AuditTrailContext : DbContext
    {
        static AuditTrailContext()
        {
            Database.SetInitializer<AuditTrailContext>(null);
        }

        //    <add name="AuditTrailContext" connectionString="Data Source=SMAUGH\SQL2008;Initial Catalog=AuditTrail;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
		public AuditTrailContext(String connectionString)
            : base(connectionString)
		{
            if (String.IsNullOrEmpty(connectionString))
                throw new InvalidOperationException("A connection string is required.");
		}

        public DbSet<AuditEntry> AuditEntries { get; set; }
        public DbSet<AuditEntryItem> AuditEntryItems { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new AuditEntryMap());
            modelBuilder.Configurations.Add(new AuditEntryItemMap());
        }
    }
}
